package com.xc.stock.domain.basic.factory;

import java.math.BigDecimal;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import com.ag.utils.SysConstant;
import com.alibaba.fastjson.JSONObject;
import com.xc.stock.constant.AccountLogType;
import com.xc.stock.domain.basic.entity.Account;
import com.xc.stock.domain.basic.entity.AccountLog;
import com.xc.stock.dto.model.AccountOperParam;
import com.xc.stock.utils.SpringUtils;

/**
 * AccountLogFactory
 *
 * @author xlfd
 * @email xlfd@gmail.com
 * @created 2022/03/25
 */
@Component
@Lazy
public class AccountLogFactory {
	public AccountLog entity(Integer actionId, AccountLogType accountLogType, Account account,
			BigDecimal amount, JSONObject pre, JSONObject after, AccountOperParam accountOperParam) {
		return AccountLog.builder()
				.accountActionId(actionId)
				.accountId(account.getId())
				.accountNo(account.getAccountNo())
				.accountType(account.getAccountType())
				.accountCurrency(account.getCurrency())
				.action(accountOperParam.getAccountAction() == null ? "" : accountOperParam.getAccountAction().code())
				.after(after == null ? "{}" : after.toJSONString())
				.amount(amount)
				.destId(account.getDestId())
				.destName(account.getDestName())
				.destPhone(account.getDestPhone())
				.ext(accountOperParam.getLogExt() == null ? "{}" : accountOperParam.getLogExt().toJSONString())
				.logContent(accountOperParam.getLogContent())
				.logType(accountLogType.code())
				.outerUid(accountOperParam.getOuterUid())
				.outerNo(accountOperParam.getOuterNo())
				.pre(pre.toJSONString())
				.role(account.getRole())
				.status(SysConstant.STATUS_NORMAL)
				.build();
	}

	public static AccountLogFactory of() {
		return SpringUtils.getBean(AccountLogFactory.class);
	}
}
